import re
import logging

from agent.common.system import sysCommand
from agent.feature.base import Feature

logger = logging.getLogger("common")

class ifconfig(Feature):
    __domain__  = "ifconfig"
    __feature__ = "mtu"
    
    def __init__(self):
        super().__init__(self.__domain__, self.__feature__)
        sysCommand("ifconfig")  # Check if 'ifconfig' available
    
    def set_value(self, value):
        sysCommand("ifconfig eth0 mtu {}".format(int(value)), log = True)
    
    def get_value(self):
        ifconfig_info = sysCommand("ifconfig eth0")
        if re.search(r"mtu (\d+)", ifconfig_info):
            return re.search(r"mtu (\d+)", ifconfig_info).group(1)

if __name__ == "__main__":
    handler = ifconfig()
    handler.backup()
    handler.set_value("8000")
    handler.rollback()
